package j5039.whcm.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import j5039.whcm.common.utils.PageUtils;
import j5039.whcm.common.utils.Query;

import j5039.whcm.product.dao.AttrGroupDao;
import j5039.whcm.product.entity.AttrGroupEntity;
import j5039.whcm.product.service.AttrGroupService;


@Service("attrGroupService")
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupDao, AttrGroupEntity> implements AttrGroupService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        LambdaQueryWrapper<AttrGroupEntity> wrapper = new LambdaQueryWrapper<>();
        Object key = params.get("key");
        Object catelogId = params.get("catelogId");
        if(catelogId!=null && (Long)catelogId!=0){
            wrapper.eq(AttrGroupEntity::getCatelogId,catelogId);
        }
        if(key!=null&&key.toString()!=""){
            wrapper.and(w-> w.like(AttrGroupEntity::getAttrGroupName,key)
                    .or().like(AttrGroupEntity::getDescript,key));
        }

        IPage<AttrGroupEntity> page = this.page(
                new Query<AttrGroupEntity>().getPage(params),
                wrapper

        );

        return new PageUtils(page);
    }

}